package com.common.autoconfig;

import java.util.Arrays;

import org.mybatis.spring.mapper.ClassPathMapperScanner;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public abstract class AbstractMapperConfig implements ImportBeanDefinitionRegistrar{

	public abstract String[] getScanPath();
	
	@Override
	public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
		String[] paths=getScanPath();
		if(paths==null||paths.length==0) {
			return ;
		}
		log.debug("Searching for mappers annotated with 自定义classpath mapper scan......."+Arrays.toString(paths));
        ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry);
        try {
            scanner.registerFilters();
            scanner.doScan(paths);
        } catch (IllegalStateException ex) {
        	log.debug("Could not determine auto-configuration package, automatic mapper scanning disabled.", ex);
        }
	}
}
